VPATH=src

htmls = *.html
filters:= $(patsubst %.lex,%,$(wildcard *.lex))
srcs:= $(patsubst src/%.newest,%.html,$(wildcard src/*.newest))

.PHONY: clean all
all: index.html parts fil

index.html: parts
	-rm $@
	for h in *.html;do echo "<a href=\"$$h\">$$h</a><br>" >>$@;done


$(srcs): %.html: %.newest $(filters)
	cat head._html >`grep $* CHAPTER |sed 's,^.* ,,'`_$@
	cat $< |./lmmfilter 	`grep $* CHAPTER |sed 's,^.* ,,'` >> `grep $* CHAPTER |sed 's,^.* ,,'`_$@
	cat tail._html >>`grep $* CHAPTER |sed 's,^.* ,,'`_$@

parts: $(srcs)

misc:
	flex misc.l
	gcc -o misc lex.yy.c helloarg.c

$(filters): %: %.lex
	flex $<
	gcc -o $@ lex.yy.c -lfl
	-rm lex.yy.c

fil: $(filters) misc

clean:
	-rm $(htmls)
	-rm *~
	-rm $(filters)
